package com.sss.controller;

import com.sss.entity.Customer;
import com.sss.service.CustomerService;
import com.sss.service.impl.CustomerServiceImpl;
import sun.misc.Request;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author sss
 * @Date: 2023/10/13/ 15:57
 * @description:
 */
@WebServlet("/AddCustomerServlet")
public class AddCustomerServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        //获取表单元素
        String custName = req.getParameter("custName");
        String custSource = req.getParameter("custSource");
        String custLevel = req.getParameter("custLevel");
        String custIndustry = req.getParameter("custIndustry");
        String custAddress = req.getParameter("custAddress");
        String custPhone = req.getParameter("custPhone");
        Customer customer=new Customer(custName,custSource,custLevel,custIndustry,custPhone,custAddress);
        //业务逻辑
        CustomerService customerService=new CustomerServiceImpl();
        customerService.saveCustomer(customer);
        req.getRequestDispatcher("index.jsp").forward(req, resp);
    }
}
